/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package technotheist.data.jbuffer;

import java.nio.ByteBuffer;
import technotheist.data.BBuffer;
import technotheist.data.BufferManager;

/**
 *
 * @author Mitch
 */
public class JBufferManager extends BufferManager {
    public static final int FLOAT = 4, INT = 4, BYTE = 1, SHORT = 2, LONG = 8, DOUBLE = 8;
    
    private boolean direct = false;
    
    public JBufferManager() {
	direct = false;
    }
    
    public JBufferManager(boolean direct) {
	this.direct = direct;
    }

    private ByteBuffer createBuffer(int size) {
	return ByteBuffer.allocate(size);
    }

    @Override
    public BBuffer<Float> createFloatBuffer(int size) {
	return new JFloatBuffer(size, createBuffer(size * FLOAT).asFloatBuffer());
    }

    @Override
    public BBuffer<Integer> createIntBuffer(int size) {
	return new JIntBuffer(size, createBuffer(size * INT).asIntBuffer());
    }

    @Override
    public BBuffer<Byte> createByteBuffer(int size) {
	return new JByteBuffer(size, createBuffer(size));
    }

    @Override
    public BBuffer<Double> createDoubleBuffer(int size) {
	return new JDoubleBuffer(size, createBuffer(size * DOUBLE).asDoubleBuffer());
    }

    @Override
    public BBuffer<Short> createShortBuffer(int size) {
	return new JShortBuffer(size, createBuffer(size * SHORT).asShortBuffer());
    }

    @Override
    public BBuffer<Long> createLongBuffer(int size) {
	return new JLongBuffer(size, createBuffer(size * LONG).asLongBuffer());
    }
}
